package zjc.bookkeeping.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import zjc.bookkeeping.R;
import zjc.bookkeeping.db.MethodBean;
import zjc.bookkeeping.tools.ToolsClass;

public class MethodListAdapter extends BaseAdapter {
    Context context;
    ImageView methodIv;
    TextView methodTv,moneyTv;
    List<MethodBean> methodBeanList;

    public MethodListAdapter(Context context, List<MethodBean> methodBeanList) {
        this.context = context;
        this.methodBeanList = methodBeanList;
    }

    @Override
    public int getCount() {
        return methodBeanList.size();
    }

    @Override
    public Object getItem(int i) {
        return methodBeanList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        MethodBean methodBean = methodBeanList.get(i);
        view = LayoutInflater.from(context).inflate(R.layout.dialog_method_item,viewGroup,false);
        methodIv = view.findViewById(R.id.dialog_method_item_iv);
        methodTv = view.findViewById(R.id.dialog_method_item_method);
        moneyTv = view.findViewById(R.id.dialog_method_item_money);
        if (!TextUtils.isEmpty(methodBean.getMethod_image())){
            methodIv.setImageResource(ToolsClass.getResourceId(methodBean.getMethod_image()));
        }
        methodTv.setText(methodBean.getMethod_name());
        if (methodBean.getMethod_money() == 0.0){
            moneyTv.setText("");
        }else {
            moneyTv.setText(String.valueOf(methodBean.getMethod_money()));
        }
        return view;
    }
}
